package com.xuyn.framework.datasource;

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

import javax.sql.DataSource;
import java.util.Map;

/**
 * @ Program     : xuyn
 * @ Description : 动态数据源
 * @ Author      : Emason
 * @ Create      : 2019-09-22 16:33
 * @ Since       : 1.0
 **/
public class DynamicDataSource extends AbstractRoutingDataSource{
    public DynamicDataSource(DataSource defaultTargetDataSource, Map<Object, Object> targetDataSources){
        super.setDefaultTargetDataSource(defaultTargetDataSource);
        super.setTargetDataSources(targetDataSources);
        super.afterPropertiesSet();
    }

    @Override
    protected Object determineCurrentLookupKey(){
        return DynamicDataSourceContextHolder.getDataSourceType();
    }
}